package com.sc.nft.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dao.DaoSchoolMaterialDao;
import com.sc.nft.entity.DaoSchoolMaterial;
import com.sc.nft.entity.dto.DaoSchoolMaterialArticleSaveAdminDTO;
import com.sc.nft.entity.dto.DaoSchoolMaterialPageAdminDTO;
import com.sc.nft.entity.vo.DaoSchoolMaterialArticlePageAdminVO;
import com.sc.nft.service.DaoSchoolMaterialService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 素材表(DaoSchoolMaterial)表服务实现类
 *
 * @author makejava
 * @since 2023-03-13 16:22:04
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class DaoSchoolMaterialServiceImpl implements DaoSchoolMaterialService {

    private final DaoSchoolMaterialDao daoSchoolMaterialDao;

    /**
     * 后台获取分页列表
     *
     * @param pageRequest
     * @return
     */
    @Override
    public Page<DaoSchoolMaterialArticlePageAdminVO> pageAdmin(DaoSchoolMaterialPageAdminDTO daoSchoolMaterialPageAdminDTO) {
        return daoSchoolMaterialDao.pageAdmin(daoSchoolMaterialPageAdminDTO);
    }

    /**
     * 删除文章
     *
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteById(Long id) {
        return daoSchoolMaterialDao.deleteById(id);
    }

    /**
     * 新增素材
     *
     * @param daoSchoolMaterialArticleSaveAdminDTO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveAdmin(DaoSchoolMaterialArticleSaveAdminDTO daoSchoolMaterialArticleSaveAdminDTO) {
        DaoSchoolMaterial daoSchoolMaterial = new DaoSchoolMaterial();
        BeanUtil.copyProperties(daoSchoolMaterialArticleSaveAdminDTO, daoSchoolMaterial);
        daoSchoolMaterial.setDaoId(6L);
        return daoSchoolMaterial.insert();
    }

}
